package user

import (
	"gohub/app/models"
	"gohub/pkg/database"
	"gohub/pkg/hash"
)

type User struct {
	models.BaseModel

	Name     string `json:"name,omitempty"`
	Email    string `json:"-"`
	Phone    string `json:"-"`
	Password string `json:"-"`

	City string `json:"city,omitempty"`
	Introduction string `json:"introduction,omitempty"`
	Avatar string `json:"avatar,omitempty"`

	models.CommonTimestampsField
}

func (model *User) Create() {
	database.DB.Create(&model)
}

func (model *User) ComparePassword(pwd string) bool {
	return hash.BcryptCheck(pwd, model.Password)
}

func (model *User) Save() (rowsAffected int64) {
	result := database.DB.Save(&model)
	return result.RowsAffected
}
